package fe.pong.tennis.gameElements ;

import fe.pong.tennis.fisica.Movimiento;
import fe.pong.tennis.input.InputConfiguration;
import fe.pong.tennis.screens.GamePlayScreen;
import flash.display.Bitmap;
import flash.geom.Point;
import openfl.Assets;

class Player extends Personaje {

	private var speed: Float;
	private var input:InputConfiguration;
	private var anchoPantalla: Int;
	private var racket:Image;
	private var angulo:Movimiento;
	private var tiempoDeRotacion: Float;
	private var tiempoUltimaIteracion: Float;

	public function new(input: InputConfiguration, x: Float, y: Float, anchoPantalla: Int, altoPantalla: Int, tamanio: Int, racketAngle: Float) {
		super();
		racket = new Image("images/racket.png", tamanio);
		_colissionArea.width = racket.width / 2;
		_colissionArea.height = racket.height;
		_colissionArea.x = _colissionArea.width;
		addChild(racket);
		tiempoDeRotacion = 0;
		tiempoUltimaIteracion = 0;
		angulo = new Movimiento(0, 10, racketAngle, tiempoDeRotacion);
		rotation = angulo.getPosicion(tiempoDeRotacion);

		this.x = x;
		this.y = y;

		this.speed = 5;
		this.input = input;
		this.anchoPantalla = anchoPantalla;
	}

	public function getShoot(): Point {
		return input.getShoot();
	}

	override public function updateLogic(time:Float) {
		super.updateLogic(time);
		var pos: Point = new Point(x, y);
		if (input.isMoving(racket)) {
			var dir: Point = input.getMove().subtract(pos);
			dir.normalize(speed);
			this.x += dir.x;
			this.y += dir.y;
		}
		if (input.isSooting(racket)) {
			trace("hola");
			tiempoDeRotacion += time - tiempoUltimaIteracion;
			rotation = angulo.getPosicion(tiempoDeRotacion);
		}
		tiempoUltimaIteracion = time;
	}

}